/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-15 14:17:31
 * @LastEditTime : 2023-08-13 16:42:51
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\Common\Conversion.jsx
 * @Description  :
 */
// ! 数据转换

import axios from 'axios'
import { API_LIST } from '../../../Api/Api'
import { project } from '../../../Data'
const { hostname } = window.location

const { client_id } = project[hostname]

// *** 数据接口
export const APIConversion = async () => {
    const res = await axios.get(API_LIST()['getApi'])
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}
// *** 菜单接口
export const MenuConversion = async () => {
    const res = await axios.get(API_LIST()['getMenuTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 小程序菜单接口
export const WeChatMenuConversion = async () => {
    const res = await axios.get(API_LIST()['getWechatMenuTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 中心类型
export const CenterTypes = async () => {
    const res = await axios.get(API_LIST()['getCenterTypeUpdateGetDownTypes'])
    return res.data.map(({ tableName }) => ({ label: tableName, value: tableName }))
}
// *** 管理端信息
export const DataSynchronization = async () => {
    const res = await axios.get(API_LIST()['getDataSynchronizationGetSelects'])
    return res.data.reduce((acc, { uuid, centName }) => {
        acc[uuid] = centName
        return acc
    }, {})
}
// *** 获取组织机构分组的CODE列表
export const OrganizationGroupList = async () => {
    const res = await axios.get(API_LIST()['getOrganizationGroupList'])
    return res.data.list.reduce((acc, { code, tableName }) => ({ ...acc, [code]: `${code} - ${tableName}` }), {})
}

// *** 中标单位
export const winningBidder = async () => {
    const noList = ['bada']
    if (noList.includes(client_id)) return {}
    else {
        const res = await axios.get(`${API_LIST()['getWinningBidder']}?pageIndex=1&pageSize=100000`)
        return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
    }
}
// *** 获取项目列表
export const ProjectList = async () => {
    const res = await axios.get(API_LIST()['getProject'])
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}
// *** 获取机构身份
export const IdentityLevel = async () => {
    const res = await axios.get(API_LIST()['getOrganizationIdentities'])
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}
// *** 获取字典树
export const DictionaryTypeConversion = async () => {
    const res = await axios.get(API_LIST()['getDictionaryTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// 获取指定字典类型
export const DictionaryListConversion = async data => {
    const res = await axios.get(`${API_LIST()['getDictionary']}?dictionaryTypeUuid=${data}`)
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}
// *** 获取投资类型
export const InvestListTreeConversion = async () => {
    const res = await axios.get(API_LIST()['getInvestListTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 获取模型
export const BimFilesConversion = async project => {
    let [BimFileOrganizationRelationProject] = Object.keys(project)
    const res = await axios.get(API_LIST()['getFiles'], {
        params: { projectUuid: BimFileOrganizationRelationProject },
    })
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}
// *** 获取安全内业树
export const SecurityDocumentTypeTree = async () => {
    const res = await axios.get(API_LIST()['getSecurityDocumentTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 获取安全类别树
export const SecurityProblemTypeTree = async () => {
    const res = await axios.get(API_LIST()['getSecurityProblemTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 获取质量类别树
export const QualityProblemTypeTree = async () => {
    const res = await axios.get(API_LIST()['getQualityProblemTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}

// *** 获取矿石类别
export const oreTypeValueEnum = async () => {
    const res = await axios.get(API_LIST()['getOreType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 获取矿石
export const oreValueEnum = async () => {
    const res = await axios.get(API_LIST()['getOre'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 人员类型
export const PersonTypeTree = async () => {
    const res = await axios.get(API_LIST()['getPersonTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}

// *** 人员类型平级
export const PersonType = async () => {
    const res = await axios.get(API_LIST()['getPersonType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 获取人员列表
export const PersonList = async () => {
    const res = await axios.get(API_LIST()['getPerson'])
    return res.data.list.reduce(
        (acc, { uuid, organizationName, tableName }) => ({ ...acc, [uuid]: `${organizationName} ${tableName}` }),
        {},
    )
}
// *** 材料类型
export const MaterialTypeTree = async () => {
    const res = await axios.get(API_LIST()['getMaterialTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 材料供应商列表
export const MaterialFactory = async () => {
    const res = await axios.get(API_LIST()['getMaterialFactory'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 材料名称类表
export const Material = async () => {
    const res = await axios.get(API_LIST()['getMaterial'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// *** 获取材料批次
export const MaterialBatch = async () => {
    const res = await axios.get(API_LIST()['getMaterialBatch'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// *** 机械类型
export const MachineTypeTree = async () => {
    const res = await axios.get(API_LIST()['getMachineTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 重点部位
export const ImportantPartTree = async () => {
    const res = await axios.get(API_LIST()['getImportantPartTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 监控位置
export const CameraPositionTree = async () => {
    const res = await axios.get(API_LIST()['getCameraPositionTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 监控列表
export const CameraList = async () => {
    const res = await axios.get(API_LIST()['getCamera'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 环境审核类型
export const EnvironmentHandleTypeTree = async () => {
    const res = await axios.get(API_LIST()['getEnvironmentHandleTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 文件类型管理
export const InfoTypeManageTree = async uuid => {
    const url = `${API_LIST()['getInfoTypeManage']}${uuid ? `?ParentUuid=${uuid}` : ''}`
    const res = await axios.get(url)
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}

// *** 指定文件分类
export const InfoTypeManageAppoint = async uuid => {
    const res = await axios.get(`${API_LIST()['getInfoTypeManage']}?ParentUuid=${uuid}`)
    return res.data
}

// *** 监理工序类型管理
export const SuperviseTypeTree = async () => {
    const res = await axios.get(API_LIST()['getSuperviseTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 试验类别
export const TestCategory = async () => {
    const res = await axios.get(API_LIST()['getTestCategory'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 试验数据来源
export const LabDataSource = async () => {
    const res = await axios.get(API_LIST()['getLabDataSource'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 试验类别
export const TestType = async () => {
    const res = await axios.get(API_LIST()['getTestType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 试验问题类别树
export const LabHandleTypeTree = async () => {
    const res = await axios.get(API_LIST()['getLabHandleTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// *** 实验类别问题平级
export const LabHandleType = async () => {
    const res = await axios.get(API_LIST()['getLabHandleType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}
// *** 报告名称类别
export const LabReportTemplates = async () => {
    const { data } = await axios.get(API_LIST()['getLabReportTemplatesTestTypesTree'])
    return {
        LabReportData: data,
        LabReportEnum: data.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {}),
    }
}

// 拌合站处理意见树
export const MixPlatHandleTypeTree = async () => {
    const res = await axios.get(API_LIST()['getMixPlatHandleTypeTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// 拌合站处理意见
export const MixPlatHandleType = async () => {
    const res = await axios.get(API_LIST()['getMixPlatHandleType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 梁类型
export const BeamType = async () => {
    const res = await axios.get(API_LIST()['getBeamType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 梁台座
export const BeamSeat = async () => {
    const res = await axios.get(API_LIST()['getBeamSeat'])
    return res.data.list.reduce(
        (acc, { uuid, tableName, organizationName }) => ({ ...acc, [uuid]: `(${organizationName}) ${tableName}` }),
        {},
    )
}

// 梁台座 - 带状态
export const BeamSeatGetNoBeamSeats = async () => {
    const res = await axios.get(API_LIST()['getBeamSeatGetNoBeamSeats'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 桥梁信息
export const BeamsStandardData = async () => {
    const res = await axios.get(API_LIST()['getBeamsStandardData'])
    return res.data
}

// 隧道信息
export const TunnelInfos = async () => {
    const res = await axios.get(API_LIST()['getTunnelInfos'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// *** 组织机构等级
export const OrganizationIdentityLevel = async num => {
    const res = await axios.get(`${API_LIST([num])['getOrganizationIdentityLevel']}`)
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}
export const getdOrganizationList = async num => {
    const res = await axios.get(`${API_LIST()['getdOrganizationList']}?IdentityLevel=${num}`)
    return res.data.reduce((acc, { value, label }) => ({ ...acc, [value]: label }), {})
}

// 合作区县
export const ProjectRegionTree = async () => {
    const res = await axios.get(API_LIST()['getProjectRegionTree'])
    return res.data
}

// 场景列表
export const Scenes = async () => {
    const res = await axios.get(`${API_LIST([])['getScenes']}`)
    return res.data.list.reduce((acc, item) => Object.assign(acc, { [item.uuid]: item.tableName }), {})
}

// PPPListTree 树形列表
export const PPPListTree = async () => {
    const res = await axios.get(API_LIST()['getPPPListTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}
// BuildListTree 树形列表
export const BuildListTree = async () => {
    const res = await axios.get(API_LIST()['getBuildListTree'])
    return [{ uuid: '00000000-0000-0000-0000-000000000000', tableName: '顶级菜单' }, ...res.data]
}

// getProjectBuildingPaymentItem
export const ProjectBuildingPaymentItem = async () => {
    const apiData = await axios.get(API_LIST()['getProjectBuildingPaymentItem'])
    return apiData.data.list.reduce((selectData, { uuid, code, tableName }) => {
        selectData[uuid] = `${code} ${tableName}`
        return selectData
    }, {})
}

// getProjectOperationPaymentItem
export const ProjectOperationPaymentItem = async () => {
    const apiData = await axios.get(API_LIST()['getProjectOperationPaymentItem'])
    return apiData.data.list.reduce((selectData, { uuid, code, tableName }) => {
        selectData[uuid] = `${code} ${tableName}`
        return selectData
    }, {})
}

// 用户分组详情
export const UserGroup = async () => {
    const res = await axios.get(API_LIST()['getUserGroup'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 获取用户信息
export const User = async () => {
    const res = await axios.get(API_LIST()['getUser'])
    let data = res.data.list.reduce(
        (acc, { uuid, tableName, fullName }) => ({ ...acc, [uuid]: `${fullName}-${tableName}` }),
        {},
    )
    return data
}

// 大屏获取组织机构
export const FrontOrganizations = async type => {
    const res = await axios.get(`${API_LIST()['getOrganizations']}${type ? `?OrgType=${type}` : ''}`)
    const data = res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
    if (type) return { [type]: '全部', ...data }
    else return data
}
// 大屏获取组织机构
export const Organizations = async () => {
    const res = await axios.get(API_LIST()['getOrganization'])
    // return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
    console.log(res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {}))
    return {}
}

export const getOrgTree = async () => {
    const res = await axios.get(`${API_LIST()['getOrgTree']}?IsByUserUuid=1`)
    return res.data
}

export const getAllOrgTree = async (uuid, is) => {
    const res = await axios.get(
        `${API_LIST()['getAllmanagedOrganizations']}?OrganizationUuid=${uuid || ''}&isEnabled=1`,
    )
    return res.data.reduce((acc, { value, label }) => ({ ...acc, [value]: label }), {})
}

// 流程类型
export const Flow = async () => {
    const res = await axios.get(API_LIST()['getFlow'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 获取枚举数据
export const EnumComments = async data => {
    const noList = ['bada']
    if (noList.includes(client_id)) return {}
    else {
        const res = await axios.get(`${API_LIST()['getEnumComments']}?enumName=${data}`)
        return res.data
    }
}

// 获取枚举数据
export const EnumCommentsAll = async () => {
    const noList = ['bada']
    if (noList.includes(client_id)) return {}
    else {
        const res = await axios.get(API_LIST()['getEnumComments'])
        return res.data
    }
}

// 大屏获取组织机构
export const EventType = async () => {
    const res = await axios.get(API_LIST()['getEventType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 大屏获取组织机构
export const SuperviseTypes = async () => {
    const res = await axios.get(API_LIST()['getSuperviseType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 劳务公司
export const LaborCompanyList = async () => {
    const res = await axios.get(API_LIST()['getLaborCompanyList'])
    return res.data.list.reduce((acc, { laborCompany }) => ({ ...acc, [laborCompany]: laborCompany }), {})
}

// 新平级组织机构获取
export const OrganizationListByPingJi = async data => {
    const res = await axios.get(`${API_LIST()['getOrganizationListByPingJ']}${data}`)
    return res.data.list.reduce((acc, { uuid, organizationName }) => ({ ...acc, [uuid]: organizationName }), {})
}

// 获取组织机构树New
export const GetProjctOrgTreeInfo = async () => {
    const res = await axios.get(API_LIST()['getProjctOrgTreeInfo'])
    return res.data
}

// 获取其他监控设备
export const GetIPBroadcast = async () => {
    const res = await axios.get(API_LIST()['getIPBroadcast'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 获取试验类型
export const GetExperimentType = async () => {
    const res = await axios.get(API_LIST()['getExperimentType'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 日志类型
export const GetSystemLogNameList = async () => {
    const res = await axios.get(API_LIST()['getSystemLogNameList'])
    const { fullNamelist, list } = res.data
    const TableName = list.map(({ tableName }) => ({ label: tableName, value: tableName }))
    const FullName = fullNamelist.map(({ fullName }) => ({ label: fullName, value: fullName }))
    return { FullName, TableName }
}

// 获取各类梁数据
export const GetBeamProduceTypeInfo = async () => {
    const res = await axios.get(API_LIST()['getBeamProduceTypeInfo'])
    const { beamSeatlist, beamTypelist, beamlist, processlist } = res.data
    const bridgeName = beamlist.reduce((acc, { tableName }) => ({ ...acc, [tableName]: tableName }), {})
    const beamSeatUuid = beamSeatlist.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
    const beamTypeUuid = beamTypelist.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
    const processUuid = processlist.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
    return { bridgeName, beamSeatUuid, beamTypeUuid, processUuid }
}

// 获取企业类型
export const GetEnterpriseCategory = async () => {
    const res = await axios.get(API_LIST()['getEnterpriseCategory'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 石料厂图片类别
export const GetEnterpriseImageCategory = async () => {
    const res = await axios.get(API_LIST()['getEnterpriseImageCategory'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 拌合站组织机构
export const GetAsphaltMixingStationNameList = async uuid => {
    const res = await axios.get(`${API_LIST()['getAsphaltMixingStationNameList']}?OrganizationUuid=${uuid}`)
    return res.data.list.reduce((acc, { uuid, organizationName }) => ({ ...acc, [uuid]: organizationName }), {})
}

// 获取形象清单列表
export const GetEngineeringTypeList = async () => {
    const res = await axios.get(API_LIST()['getEngineeringTypeList'])
    return res.data.list.reduce((acc, { uuid, tableName }) => ({ ...acc, [uuid]: tableName }), {})
}

// 获取所有组织机构信息
export const AllOrganizationList = async () => {
    const res = await axios.get(API_LIST()['getAllOrganizationList'])
    return res.data
}

// 获取所有组织机构信息 getAllmanagedOrganizations
export const GetAllmanagedOrganizations = async () => {
    const res = await axios.get(API_LIST()['getAllmanagedOrganizations'])
    return res.data.reduce((acc, { value, label }) => ({ ...acc, [value]: label }), {})
}

// 获取分公司列表
export const getCompanyList = async () => {
    const res = await axios.get(API_LIST()['getCompanyList'])
    return res.data
}

// 获取专业列表
export const GetProfessionalMajorCategory = async () => {
    const res = await axios.get(API_LIST()['getProfessionalMajorCategory'])
    const data = JSON.parse(
        JSON.stringify(res.data)
            .replace(/tableName/g, 'label')
            .replace(/uuid/g, 'value'),
    )
    return data
}
// 获取证书列表
export const GetProfessionalCategory = async () => {
    const res = await axios.get(API_LIST()['getProfessionalCategory'])
    const data = JSON.parse(
        JSON.stringify(res.data)
            .replace(/tableName/g, 'label')
            .replace(/uuid/g, 'value'),
    )
    return data
}
// 证书名称
export const GetProfessionalCategoryNameList = async () => {
    const res = await axios.get(API_LIST()['getProfessionalCategoryNameList'])
    return res.data.list.map(({ tableName }) => ({ label: tableName, value: tableName }))
}
// 证书专业
export const GetProfessionalCertificateMajorNameList = async () => {
    const res = await axios.get(API_LIST()['getProfessionalCertificateMajorNameList'])
    return res.data.list.map(({ tableName }) => ({ label: tableName, value: tableName }))
}
// 大专业
export const GetProfessionalMajorCategoryNameList = async () => {
    const res = await axios.get(API_LIST()['getProfessionalMajorCategoryNameList'])
    return res.data.list.map(({ tableName }) => ({ label: tableName, value: tableName }))
}
// 小专业
export const GetProfessionalSubMajorNameList = async () => {
    const res = await axios.get(API_LIST()['getProfessionalSubMajorNameList'])
    return res.data.list.map(({ tableName }) => ({ label: tableName, value: tableName }))
}
// 职称
export const GetProfessionalOriginalTitleNameList = async () => {
    const res = await axios.get(API_LIST()['getProfessionalOriginalTitleNameList'])
    return res.data.list.map(({ tableName }) => ({ label: tableName, value: tableName }))
}
